import { UserProfilesAPI } from "../../request/api"
export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: "hjx",
            coin: 99,
            headImg: require("../../assets/img/service.848ec511.png")
        },
        cartTotal: 9
    },
    mutations: {
        //修改登录状态
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo;
            state.cartTotal = payload.cartTotal;
        },
        //初始化仓库属性
        initUserInfo(state) {
            state.userInfo = {
                nickName: "--",
                coin: "--",
                headImg: require("../../assets/img/userImg.f8bbec5e.png")
            },
                state.cartTotal = 0
        }
    },
    actions: {
        async asyncchangeUserInfo({
            commit
        }) {
            //1.请求用户信息
            let user = await UserProfilesAPI();
            // console.log("用户信息...", user);
            //2.更新vuex中用户信息 调用mutations
            commit("changeUserInfo", user.data)
        }
    }
}